package com.ruoyi.flowable.manager;

import java.util.Date;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import com.ruoyi.flowable.model.jpa.LeaveJpaEntity;
import com.ruoyi.flowable.service.ILeaveEntityService;
//jpa 调用例子
@Component("leaveEntityManager")
public class LeaveEntityManager {

    @Resource
    protected ILeaveEntityService leaveEntityService;

    @Transactional
    public LeaveJpaEntity newLeave(DelegateExecution execution) {
        LeaveJpaEntity leave =new LeaveJpaEntity();
        leave.setProcessInstanceId(execution.getProcessInstanceId());
        leave.setUserId(execution.getVariable("applyUserId").toString());
        leave.setStartTime((Date) execution.getVariable("startTime"));
        leave.setEndTime((Date) execution.getVariable("endTime"));
        leave.setLeaveType(execution.getVariable("leaveType").toString());
        leave.setReason(execution.getVariable("reason").toString());
        leave.setApplyTime(new Date());
        return  leaveEntityService.SaveEntity(leave);
    }

    public LeaveJpaEntity getLeave(Integer id) {
        return leaveEntityService.findEntityById(id);
    }

}


